// const Base_URL = "http://localhost:8080/"
/**
 * 从URL中查询出指定的参数值
 * 传入url，比如 http://localhost:8080/stuInfo.html?username=123&password=123456
 * @param url
 * @returns {null}
 */
window.getParameter = (url, parameterName) => {
    let temp = url.split("?")
    if (temp.length != 2) {
        //url格式不规范
        return null
    }
    let parameters = temp[1].split("&")
    for (let i = 0; i < parameters.length; i++) {
        let param = parameters[i].split("=")
        if (param.length != 2) {
            //参数格式不规范
            return null
        }
        //找到指定的参数
        if (param[0] == parameterName) {
            return param[1]
        }
    }
}
/**
 * 判断是否登录
 * @returns {boolean}
 */
window.isLogin = () => {
    let user;
    try {
        user = JSON.parse(localStorage.getItem("user"));
    } catch (error) {
        console.error("Error parsing user data:", error);
        user = undefined;
    }
    if (user == undefined || user == null) {
        return false
    } else {
        return true
    }
}
/**
 * 判断是否为管理员
 * @returns {boolean}
 */
window.isAdmin = () => {
    if (!isLogin()) {
        return false
    }
   let user = JSON.parse(localStorage.getItem("user"));
    return user.role == "admin"
}
/**
 * 判断是否为老师
 * @returns {boolean}
 */
window.isTeacher = () => {
    if (!isLogin()) {
        return false
    }
   let user = JSON.parse(localStorage.getItem("user"));
    return user.role == "teacher"
}